package com.rx.base.demo.controller;

import com.rx.base.demo.common.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "测试SwaggerAPI Annotation", tags = {"测试SwaggerAPI"})
@RestController
@RequestMapping("/swagger")
public class SwaggerController {

    @GetMapping("/no_params")
    public String noParams() {
        return "OK";
    }

    @GetMapping("/one_params")
    @ApiOperation(value = "one parameters", notes = "一个参数的设计", nickname = "nickname one parameter")
    public BaseResult<String> oneParams(String name) {
        return BaseResult.success();
    }


    @ApiOperation(value = "两个参数的测试", notes = "两个参数的测试")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name="name", value="用户名", dataTypeClass = String.class, required = true),
                    @ApiImplicitParam(name="age", value="年龄", dataTypeClass = Integer.class, required = true)
            }
    )
    @GetMapping("/two_params")
    public BaseResult<String> twoParams(String name, int age) {
        return BaseResult.success(name + ": " + age);
    }

    @ApiOperation(value = "参数在路径中", notes = "自定义返回Response", response = BaseResult.class)
    @ApiImplicitParam(name="param", value="参数", example = "tom", dataTypeClass = String.class, required = true)
    @GetMapping("/path_params/{param}")
    public BaseResult<String> paramInPath(@PathVariable String param) {
        return BaseResult.success();
    }

}